/**
 * iSight edit
 * 
 * Licensed for Servitius
 * 
 * 
 */
 
 
/**
  *
  * CKEDITOR stuff - remove, create editor
  *
  */
function createEditor(html, config)
{
    if ( editor )
        return;

    // Create a new editor inside the <div id="editor">, setting its value to html
    editor = CKEDITOR.appendTo( 'editor-textarea', config, html );
}

function removeEditor(toElement)
{
    if ( !editor )
        return;

    // Retrieve the editor contents. In an Ajax application, this data would be
    // sent to the server or used in any other way.
    document.getElementById( 'editorcontents' ).innerHTML = html = editor.getData();
    document.getElementById( 'toElement' ).style.display = '';

    // Destroy the editor.
    editor.destroy();
    editor = null;
}

var editor;


function editArticle(parent){
    if(!parent){
        // Error handling if variable not set
        alert('Error: editArticle parent not set.');
        return false;
    } 
    
    // ezt ajax get-tel kel majd helyettesíteni!!!!!
    var editableText = $(parent).html();
    //megsemmisítjük a már létező texteditorokat
    if ( editor )
		editor.destroy();
    // rátöltjük a ckeditort a textareankra
    editor = CKEDITOR.replace( 'editor_textarea', { 
            language: 'hu'
        } );
    // betöltjük a megszerzett szerkesztendő szöveget a ckeditorba
    CKEDITOR.instances.editor_textarea.setData(editableText);
    
    $("#admin_editor").dialog({
        title: 'Szerkesztés - ' + parent,
        height: $(parent).height()+20,
        width: $(parent).width()+20,
        modal: true
    });
    return true;
}


$(document).ready(function() {
    /**
     * ez a rész kell ha mousover lesz és szerkesztés
     */

    console.log("admin js loaded");
   
    $("#servitius_content-edit").hide();
    $('#servitius_content').hover(function(){
        $(this).addClass("divHover")
        $("#servitius_content-edit").show("fast")
    }, function(){
        $(this).removeClass("divHover");
        $("#servitius_content-edit").hide("fast")
    });
    
    $("#edit-div-number").button().click(function(){
        console.log("Hello world");
        $("#dialog-form").dialog( "open" );
    });

});


